let CountDown = require("CountDown");

var {
    TexasPokerActions,
    TexasPokerBetType
} = require("Texas")


cc.Class({
    extends: cc.Component,

    properties: {
        filling: cc.Label,
        total: cc.Label,
        maxFilling: cc.Label,
        maxBet: 0,//最大加注：底注的20倍
        bottomBet: 10,//主播设置的底注
        fillingBet: 0,//玩家加注
        countDown: CountDown,
        memberIdP: 0,
        actionType: 0,
    },

    // use this for initialization
    onLoad: function () {
        // this.registerEvent();
    },

    registerEvent: function () {
        window.sock.node.on("jiazhu", (e) => {
            this.node.active = true;
        })

        window.sock.node.on("11-14", (e) => {//改变玩家基础数据:Casino_ChangePlayerInfoVo
            this.memberIdP = e.detail.index;
        })

        //  gameType: number;               //Int
        //     actionType: number;			    //Int 弹窗类型
        //     action: number;                  //UInt
        //     p1: number; //Int
        //     p2: number; //Int
        //     p3: number; //Int
        //     p4: number; //Int
        window.sock.node.on("11-17", (e) => {//通知客户端打开弹窗:Casino_OpenAction
            this.actionType = e.detail.actionType;
        })
    },

    start: function () {
        this.bottomBet = window.room.minJoinBets;
        this.maxBet = this.bottomBet * 20
        this.reset()
        this.showProgress()
    },

    setFilling() {
        if (this.fillingBet > this.maxBet) {
            return;
        }
        this.fillingBet += this.bottomBet
        this.total.string = '本次总计加注：' + this.fillingBet.toString()
    },

    reset() {
        this.init();
    },

    init() {
        this.fillingBet = 0;
        this.filling.string = '加注\n+' + this.bottomBet.toString()
        this.total.string = '本次总计加注：0'
        this.maxFilling.string = '本次加注最大金额' + this.maxBet + '砖石'
    },

    btn_ok() {
        if (this.fillingBet === 0) {
            window.sock.action({ actionType: this.actionType, action: TexasPokerActions.TexasPokerAction_Pass });
        } else {
            this.fillingF();
        }
        this.node.active = false;
        this.countDown.stopFillingCount();
    },

    showProgress() {
        this.countDown.startFillingCount(10)
        this.countDown.complete = () => { this.btn_ok() }

    },

    /**
     * 加注
     */
    fillingF() {
        this.countDown.stopFillingCount();
        this.node.active = false;
        window.sock.bet({ memberId: this.memberIdP, betType: TexasPokerBetType.TexasPokerBetType_Raise, golds: this.fillingBet });
    },



});
